/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        queue<Node*> que;
        vector<vector<int>> vec;
        if(root != nullptr)
            que.push(root);

        while(!que.empty())
        {
            vector<int> tmp;    // 统计本层的结点
            for(int i = que.size(); i > 0; --i)
            {
                Node* t = que.front();
                que.pop();
                tmp.push_back(t->val);
                for(Node* child : t->children)  // 让下一层结点入队
                {
                    if(child != nullptr)
                        que.push(child);
                }
            }
            vec.push_back(tmp);
        }
        return vec;
    }
};